﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common;
using System.Web.Security;
using System.Windows.Forms;
using System.Collections;
using System.Data;

namespace BLL
{
    public class LogOP
    {
        public static bool InserLogCallback(ref WFNetLib.Log.SystemLogData l)
        {
//             l.Operator = AppInfo.Operator;
//             switch (l.LogType)
//             {
//                 case (int)LogType.EmptyTaskCode:
//                     l.LogContent = "条码为:" + l.LogContent + " 获得的护照信息为空";
//                     l.LogRemark = "未知条码";
//                     break;
//                 case (int)LogType.WebService:
//                     l.LogContent = Properties.Settings.Default.BLL_wsdl_Service1 + ":" + l.LogContent;
//                     l.LogRemark = "web 服务出错";
//                     break;
//                 case (int)LogType.MultiTaskCode:
//                     l.LogContent = "条形码为:" + l.LogContent + "的护照从服务器获得" + l.LogRemark + "条信息";
//                     l.LogRemark = "存疑条码";
//                     break;
//                 case (int)LogType.errorPassportInfo:
//                     l.LogContent = "从服务器获得条形码为" + l.LogContent + "的护照信息数据有误:" + l.LogRemark;
//                     l.LogRemark = "错误护照信息";
//                     break;
//                 case (int)LogType.PassportPortCantOpen:
//                     l.LogContent = "与护照通信的串口无法打开:" + l.LogContent + "       " + l.LogRemark;
//                     l.LogRemark = "通信端口无法打开";
//                     break;
//                 case (int)LogType.PassportPortTimeOut:
//                     l.LogContent = "通信超时，架子号为:" + l.LogContent + ",命令为:" + l.LogRemark;
//                     l.LogRemark = "通信超时";
//                     break;
//                 case (int)LogType.PassportPortSumError:
//                     l.LogContent = "校验和错误，架子号为:" + l.LogContent + ",命令为:" + l.LogRemark;
//                     l.LogRemark = "校验错误";
//                     break;
//                 //case Common.LogType.                    
 //           }
            return true;
        }
        static public void SetLogTypeCombobox(ComboBox cb)
        {
//             ArrayList LogTypes = new ArrayList();
//             LogTypes.Add(new LogTypeForCombobox("全部", 0));
// //             if (Roles.IsUserInRole(AppInfo.Operator, "ShowLog_PassportOperation"))
// //             {
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.护照存入.ToString(), (int)LogTypeForShow.护照存入));
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.护照取出.ToString(), (int)LogTypeForShow.护照取出));
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.护照位置变动.ToString(), (int)LogTypeForShow.护照位置变动));
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.编辑护照信息.ToString(), (int)LogTypeForShow.编辑护照信息));
// //            }
// //            if (Roles.IsUserInRole(AppInfo.Operator, "ShowLog_WebServiceError"))
// //            {
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.网络服务连接失败.ToString(),(int)LogTypeForShow.网络服务连接失败));
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.护照信息为空.ToString(), (int)LogTypeForShow.护照信息为空));
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.条码一对多.ToString(), (int)LogTypeForShow.条码一对多));
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.护照信息错误.ToString(), (int)LogTypeForShow.护照信息错误));
// //            }
// //           if (Roles.IsUserInRole(AppInfo.Operator, "ShowLog_Detect"))
// //            {
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.护照丢失.ToString(), (int)LogTypeForShow.护照丢失));
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.护照突入.ToString(), (int)LogTypeForShow.护照突入));
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.护照未知取出.ToString(), (int)LogTypeForShow.护照未知取出));
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.护照未知放入.ToString(), (int)LogTypeForShow.护照未知放入));
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.护照位置一对多.ToString(), (int)LogTypeForShow.护照位置一对多));
// //            }
// //            if (Roles.IsUserInRole(AppInfo.Operator, "ShowLog_Advanc"))
// //            {
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.检测电路串口无法打开.ToString(), (int)LogTypeForShow.检测电路串口无法打开));
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.检测电路校验和失败.ToString(), (int)LogTypeForShow.检测电路校验和失败));
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.与检测电路通信超时.ToString(), (int)LogTypeForShow.与检测电路通信超时));
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.检测单元出错.ToString(), (int)LogTypeForShow.检测单元出错));
//                 LogTypes.Add(new LogTypeForCombobox(LogTypeForShow.护照数据库操作失败.ToString(), (int)LogTypeForShow.护照数据库操作失败));
// //            }
//             cb.DataSource = LogTypes;
//             cb.DisplayMember = "logTypeForShow";
//             cb.ValueMember = "LogTypeValue";
        }
        static public string GetLogType()
        {
            StringBuilder Ret = new StringBuilder();
            string role;
            string[] roles=Roles.GetRolesForUser(AppInfo.Operator);
            foreach(string t in Enum.GetNames(typeof(LogType)))
            {
                role = string.Format("ShowLog_{0}", t);
                if (roles.Contains(role))
                    Ret.Append(string.Format("LogType={0} OR ",Convert.ToInt32(Enum.Parse(typeof(LogType), t))));
            }
            if (Ret.Length != 0)
                Ret.Remove(Ret.Length - 4, 4);
            return Ret.ToString();           
        }        
    }
    public class LogTypeForCombobox
    {
        private string logTypeForShow;

        public string LogTypeForShow
        {
            get { return logTypeForShow; }
            set { logTypeForShow = value; }
        }
        private int logTypeValue;

        public int LogTypeValue
        {
            get { return logTypeValue; }
            set { logTypeValue = value; }
        }
        public LogTypeForCombobox(string show,int value)
        {
            logTypeForShow = show;
            logTypeValue = value;
        }

    }
}
